package com.jingogo.controller;

import com.jingogo.common.Result;
import com.jingogo.entity.Promotion;
import com.jingogo.service.PromotionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/promotion")
@Tag(name = "促销活动", description = "促销活动相关接口")
public class PromotionController {
    @Autowired
    private PromotionService promotionService;

    @PostMapping("/add")
    @Operation(summary = "新增促销活动", description = "新增促销活动")
    @PreAuthorize("hasRole('ADMIN')")
    public Result<String> addPromotion(@RequestBody Promotion promotion) {
        promotionService.addPromotion(promotion);
        return Result.success("促销活动添加成功");
    }

    @GetMapping("/list")
    @Operation(summary = "促销活动列表", description = "获取促销活动列表")
    public Result<List<Promotion>> listPromotions() {
        return Result.success(promotionService.listPromotions());
    }
} 